# -*- coding: utf-8 -*-
from permission.models import Permission,View_permission
from django.shortcuts import render
def check_per(view_name):
    def wrapper(func):
        def function(request, *args, **kwargs):
            user = request.user
            user_permission = []
            view_permission = View_permission.objects.filter(view_name=view_name).first()
            permission_name = view_permission.view_permiss__permission_name
            permissions = user.permission_name.all()
            for user in permissions:
                user_permission.append(user.view_name__view_name)
            if permission_name in user_permission:
                return func(request, *args, **kwargs)
            return render(request,'/permission/error.html', {'error': u'你没有这个权限'})

        return function

    return wrapper